<template>
	<view class="container">
		
		<view class="bg" :style="{backgroundImage: 'url('+ $util.img('image/elferly_bg.png') +')'}">
			<view class="info">
				 <view class="name">精细养老无忧</view>
				 <view class="font-24" style="color: #fff;">贴心照护安心相伴，岁月静好乐享无忧！</view>
			</view>
		</view>
		<u-navbar
		     :title="title"
		     @rightClick="goBack()"
		     :autoBack="true"
		     bgColor="transparent"
		     color="#ffffff"
		     leftIconColor="#ffffff"
		     :titleStyle="titleStyle"
		     :placeholder="true"
		 >
		 </u-navbar>
		 
		 
		 <view class="main rel">
		 	<view class="boxPanel flex" v-for="(item,index) in navlist" :key="index" @click="goTo(item)">
		 		<image :src="$util.img(item.image)" mode="aspectFill" class="icon" :lazy-load="true"></image>
		 		  <view class="flex-1 flex-column">
		 			<view class="text-bold">{{item.category_name}}</view>
		 			<view class="font-24  c-89">{{item.description}}</view>
		 		  </view>
		 		<u-icon name="arrow-right" color="#788096" size="14"></u-icon>
		 	</view>
			<view class="boxPanel flex" v-for="(item,index) in articleList" :key="index" @click="goArticleDetail(item)">
		 		<image :src="$util.img(item.icon)" mode="aspectFill" class="icon" :lazy-load="true"></image>
		 		  <view class="flex-1 flex-column">
		 			<view class="text-bold">{{item.title}}</view>
		 			<view class="font-24  c-89">{{item.describe}}</view>
		 		  </view>
		 		<u-icon name="arrow-right" color="#788096" size="14"></u-icon>
		 	</view>
		 </view>
		 
		 <!-- 登录 -->
		 <login-pop ref="loginDialog"></login-pop>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
				  'color': '#ffffff'
				},
				title: '',
				navlist: [],
				articleList: [],

			}
		},
		onLoad() {
			if (!uni.getStorageSync('token')) this.$refs.loginDialog.open();
			this.getIndex();
			this.getArticleList()
		},
		methods: {
			goBack() {
				// 判断路由是否有上一页，如果有则返回上一页，否则返回到首页
				if (getCurrentPages().length > 1) {
					uni.navigateBack()
				}else {
					this.$util.redirectTo('/pages/index/index')
				}
			},
			goArticleDetail(item) {
				this.$util.redirectTo('/otherpages/elderly/description?id='+item.article_id)
			},
			goTo(item) {
				this.$util.redirectTo('/otherpages/elderly/care?title='+item.category_name+'&category_id='+item.category_id)
			},
			getIndex() {
				this.$api.sendRequest({
			      url: "/api/yanglao/categorylists",
			      data: {},
			      success: res => {
			        if(res.code == 0) {
						this.navlist = res.data;
			        }else {
						this.$util.showToast(res.message);
					}
			      }
			    })
			},
			getArticleList() {
				this.$api.sendRequest({
			      url: "/api/yanglao/article",
			      data: {},
			      success: res => {
			        if(res.code == 0) {
						this.articleList = res.data;
			        }else {
						this.$util.showToast(res.message);
					}
			      }
			    })
			},
		}
	}
</script>

<style lang="scss" scoped>
.bg {
	width: 750rpx;
	height: 484rpx;
	background-position: 100% 100%;
	background-repeat: no-repeat;
	background-size: cover;
	.info {
		text-align: left;
		padding: 200rpx 30rpx 0 30rpx;
		.name {
			font-size: 40rpx;
			font-weight: bold;
			margin-bottom: 24rpx;
			color: #fff;
		}
	}
}
.main {
	margin-top: -230rpx;
}
.boxPanel {
	.icon {
	  width: 104rpx;
	  height: 104rpx;
	  margin-right: 20rpx;
	}
	
}
</style>
